﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _6_变量 : System.Web.UI.Page
{
    private int i = 1;//每次请求过来都会new一个新的实现了IHttphandle接口的类“变量1”的实例进行处理，用完了就GC掉了，
                        //所以不会保持上次的值(有时会考)
    private static int j = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Cookies["MySessionId"] == null)
        {
            string sessionId = Guid.NewGuid().ToString();
            Response.SetCookie(new HttpCookie("MySessionId", sessionId));
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
       // i++;
       // Label1.Text = i.ToString();
        j++;
        Label1.Text = j.ToString();
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        string sessionId = Request.Cookies["MySessionId"].Value;
        IDictionary<string, object> session = SessionManager.GetSession(sessionId);
        session["服务器端数据"] = DateTime.Now.ToString();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        string sessionId = Request.Cookies["MySessionId"].Value;
        IDictionary<string, object> session = SessionManager.GetSession(sessionId);
        Label1.Text = session["服务器端数据"].ToString();
    }
}